package FWK.util;

import java.awt.Dimension;
import java.io.IOException;
import java.util.List;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

import FWK.components.FwkButton;
import FWK.components.FwkTextField;
import FWK.core.FwkErrorMannager;

public class FwkComponentsFactory {

	public static FwkTextField createTextField() {
		return createTextField(100, false);
	}

	public static FwkTextField createTextField(int characters, boolean isStatic) {
		FwkTextField txt = new FwkTextField();
		Dimension dim = new Dimension(characters, 20);
		txt.setSize(dim);
		txt.setPreferredSize(dim);
		txt.setMinimumSize(dim);
		if(isStatic)
			txt.setMaximumSize(dim);
		return txt;
	}

	public static FwkButton createImagedButton(String path, int hints, int width) {
		FwkButton button = new FwkButton();
		button.setOpaque(true);
		try {
			button.setIcon(FwkViewsUtils.getIcon(path, width, hints));
		} catch (IOException e) {
			FwkErrorMannager.error(e, "No se pueden cargar las imagenes", null);
		}
		return button;
	}

	public static FwkButton createImagedButton(String path) {
		return createImagedButton(path, 25, 25);
	}

	public static JPopupMenu createPopupMenu(List<JMenuItem> menuItems) {
		JPopupMenu menu = new JPopupMenu();
		menu.setBorderPainted(true);
		// menu.setBackground(Color.red);
		for (JMenuItem item : menuItems) {
			item.setBorderPainted(true);
			// item.setBackground(Color.red);
			menu.add(item);
		}
		return menu;
	}

}
